package com.api.shopapi.mapper;


import com.api.shopapi.entity.Menu;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface MenuMapper {

    @Insert("insert into menu values(#{menu.MenuCode},#{menu.ParentMenuCode},#{menu.Name},#{menu.Url}," +
            "#{menu.Icon},#{menu.Sort})")
    public int insert(@Param("menu") Menu menu);


    @Delete("delete from menu where menuCode=#{menuCode}")
    public int deleteByMenuCode(@Param("menuCode") String menuCode);


    @Update("update menu set ParentMenuCode=#{menu.ParentMenuCode},Name=#{menu.Name}," +
            "Url=#{menu.Url},Icon=#{menu.Icon},Sort=#{menu.Sort} where MenuCode=#{menu.MenuCode}")
    public int updateByMenuCode(@Param("menu") Menu menu);


    @Select("select * from menu where menuCode=#{menuCode} limit 1")
    public Menu getByMenuCode(@Param("menuCode") String menuCode);


    @Select("select * from menu order by Sort desc")
    public List<Menu> getList();

    @Select("select * from menu where parentMenuCode=#{parentMenuCode} order by Sort desc")
    public List<Menu> getListByParentMenuCode(String parentMenuCode);

    @Select("select m.* from role_menu_rel rmr,menu m where rmr.MenuCode=m.MenuCode and rmr.roleCode=#{roleCode} " +
            "and m.parentMenuCode=#{parentMenuCode} order by m.Sort desc")
    public List<Menu> getListByRoleCodeParentMenuCode(@Param("roleCode") String roleCode,@Param("parentMenuCode") String parentMenuCode);



}
